package com.leetcode.partition5;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

/**
 * @author `RKC`
 * @date 2022/2/18 10:33
 */
public class LC493翻转对_树状数组 {

    private static final int N = 50010 * 2;
    private static Set<Long> set = new TreeSet<>();
    private static Map<Long, Integer> map = new HashMap<>(N);
    private static int[] c = new int[N];
    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        int[] nums = new int[ss.length];
        for (int i = 0; i < ss.length; i++) nums[i] = Integer.parseInt(ss[i]);
        writer.write(reversePairs(nums) + "\n");
        writer.flush();
    }

    public static int reversePairs(int[] nums) {
        n = nums.length;
        //离散化
        for (int i = 0; i < n; i++) {
            set.add((long) nums[i] - 1);
            set.add(nums[i] * 2L);
        }
        int idx = 0, ans = 0;
        for (long num : set) map.put(num, ++idx);
        // i < j, nums[i] > 2*nums[j] => nums[i]/2 > nums[j]
        for (int i = n - 1; i >= 0; i--) {
            int val = map.get((long) nums[i] - 1);
            ans += ask(val);
            add(map.get(nums[i] * 2L), 1);
        }
        return ans;
    }

    private static int ask(int x) {
        int res = 0;
        for (int i = x; i != 0; i -= lowbit(i)) res += c[i];
        return res;
    }

    private static void add(int x, int k) {
        for (int i = x; i <= N; i += lowbit(i)) c[i] += k;
    }

    private static int lowbit(int x) {
        return x & -x;
    }
}
